<?php $section = 'Users'; ?>
<?php require_once '../inc/functions.php'; ?>
<?php require_once 'data.php'; ?>
<?php 
	$FirstName =  (string)$_POST['FirstName'];
	$LastName = (string)$_POST['LastName'];
	$Email = (string)$_POST['Email'];
	$Password = (string)$_POST['Password'];
	$PhoneNumber = (string)$_POST['PhoneNumber'];
	$Facebook = (string)$_POST['Facebook'];
	
$editUsers = array('FirstName' => $FirstName,
			  	   'LastName' => $LastName,
			 	   'Password' => $Password);
			  
$editCM = array('Email' => $Email,
				'Phone' => $PhoneNumber,
				'Facebook' => $Facebook);
	$id = $_REQUEST['id'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Core[nerd]-Users</title>
<link href="../inc/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="container">

<?php include('../inc/nav.php'); ?>

<?php
	$conn = getConnection();	
	$result = $conn->query("SELECT * FROM 2011_Users WHERE id='$id'");
	$rs = $result->fetch_assoc();
	if (isset($id))
	{
		$sql = "UPDATE 2011_Users SET "
		. "FirstName = '$FirstName',"
		. "LastName = '$LastName',"
		. "Password = '$Password' "
		. "WHERE id='$id'"; 
		echo '<p>User Updated!</p>';
	}
	else {
		$sql = "INSERT INTO 2011_USERS (FirstName, LastName, Password) VALUES "
		. "('$FirstName', '$LastName', '$Password')";
		echo '<p>User Inserted!</p>';
	}
	$conn->query($sql);
	$error = $conn->error;	
	echo $error;
	$conn->close();
?>

<?php
	$conn = getConnection();	
	$result = $conn->query("SELECT * FROM 2011_ContactMethods WHERE User_id='$id'");
	$rs = $result->fetch_assoc();
	$CM_id = $rs['id'];
	if (isset($CM_id))
	{
		$sql = "UPDATE 2011_ContactMethods SET "
		. "Email = '$Email',"
		. "Phone = '$PhoneNumber',"
		. "Facebook = '$Facebook' "
		. "WHERE id='$CM_id'"; 
		echo '<p>User Contacts Methods Updated!</p>';
	}
	else {
		$sql = "INSERT INTO 2011_ContactMethods (User_id, Email, Phone, Facebook) VALUES "
		. "('$id', '$Email', '$PhoneNumber', '$Facebook')";
		echo '<p>User Contacts Methods Inserted!</p>';
	}
	$conn->query($sql);
	$error = $conn->error;	
	echo $error;
	$conn->close();
	echo '</br><a href="../games.php">Continue Shopping</a>';
?>


</div>
</body>
</html>